package cn.micai.base.thread;

import com.google.common.util.concurrent.ThreadFactoryBuilder;

import java.util.ArrayList;
import java.util.List;
import java.util.concurrent.*;

/**
 * 描述：
 * <p>
 *
 * @author: 赵新国
 * @date: 2018/3/21 17:02
 */
public class MultiThreadTest {

    private static  final ThreadFactory threadFactory = new ThreadFactoryBuilder().setNameFormat("thread-%d").build();
    private static  final ExecutorService executor = new ThreadPoolExecutor(2, 5, 60L, TimeUnit.SECONDS, new LinkedBlockingQueue<Runnable>(), threadFactory);

    public static void main(String [] args) {

        executor.execute(new MultiThreadToPdf(1L, new ArrayList<>()));

        /*executor.execute(new Runnable() {
            @Override
            public void run() {
                for (int i=0;i<1000;i++) {
                    System.out.println("hello world !");
                }
            }
        });*/

    }

    private static class MultiThreadToPdf implements Runnable {
        Long userId;
        List<Long> billIds;
        public MultiThreadToPdf(Long userId, List<Long> billIds) {
            this.userId = userId;
            this.billIds = billIds;
        }
        @Override
        public void run() {
            long start = System.currentTimeMillis();
            for (int i=0; i<200000; i++) {
                System.out.println("aaaaa");
            }
            System.out.println("耗时：" + (System.currentTimeMillis()-start) + " 毫秒!");
        }
    }
}
